home *** CD-ROM | disk | FTP | other *** search
/ Enter 2006 February / enter-2006-02.iso / files / Illustrator_CS2_ue_TryOut.exe / bridge / Adobe Bridge 1.0.msi / Data1.cab / _3scriptsPane.jsx < prev    next >
Encoding:
Text File  |  2005-03-24  |  8.4 KB  |  262 lines

  1. /**************************************************************************
  2. *
  3. *  @@@BUILDINFO@@@ 33scriptsPane.jsx 1.0.0.61 06-Mar-2005
  4. *  Copyright 2005 Adobe Systems Incorporated
  5. *  All Rights Reserved.
  6. *
  7. * NOTICE:  All information contained herein is, and remains the property of
  8. * Adobe Systems Incorporated  and its suppliers,  if any.  The intellectual 
  9. * and technical concepts contained herein are proprietary to  Adobe Systems 
  10. * Incorporated  and its suppliers  and may be  covered by U.S.  and Foreign 
  11. * Patents,patents in process,and are protected by trade secret or copyright 
  12. * law.  Dissemination of this  information or reproduction of this material
  13. * is strictly  forbidden  unless prior written permission is  obtained from 
  14. * Adobe Systems Incorporated.
  15. **************************************************************************/
  16.  
  17. // Code to add to the Scripts pane
  18. // The output field of the scripts pane is a list box. The array scriptIDs
  19. // takes a list of all script IDs. This list is used during Document.onSave()
  20. // to determine if a document belongs to a target app and whether that app
  21. // should receive a PutScript message.
  22.  
  23. // Get the script IDs and populate the Scripts pane. Each line contains
  24. // two words. The first, is the display name, while the second word is the 
  25. // script ID. The script ID must be a path name if it starts with '/' or '~'. If 
  26. // it starts with anything else but a '(' (which is reserved for new scripts),
  27. // it is app specific, and the app will have to supply the script on request.
  28. // Application-supplied script IDs should be system unique.
  29.  
  30. // The "info" property is an object with script IDs as property names. Each
  31. // object has the properties displayName, scriptID, status and readOnly. If a script 
  32. // is not executable, the status is "noexec". The object is also attached to
  33. // the list item.
  34.  
  35. window.scripts.info = {};
  36.  
  37. window.scripts.getScripts = function()
  38. {
  39.     var bt = BridgeTalk.create (currentDebugger.target, "GetScripts");
  40.     bt.headers.Engine = currentDebugger.engine;
  41.     bt.onOwnResult = function (bt)
  42.     {
  43.         var target = this.target.replace ("#estk", "");
  44.         // clear all lists
  45.         window.scripts.output.removeAll();
  46.         window.scripts.info = {};
  47.         var reply = bt.splitBody();
  48.         for (var i = 0; i < reply.length; i++)
  49.         {
  50.             // if we have an empty line, this is the separator between scripts and additional info
  51.             if (reply [i].length == 0)
  52.                 break;
  53.             // fill in what we have got
  54.             var displayName = reply [i][0];
  55.             var scriptID    = reply [i][1];
  56.             var status        = reply [i][2];
  57.             var readOnly    = reply [i][3];
  58.             if (!status)
  59.                 status = "exec";
  60.             // backwards compatibility
  61.             if (status == "active")
  62.                 status = "exec";
  63.             // do we have both?
  64.             if (displayName.length && scriptID.length)
  65.             {
  66.                 // Remove .LNK from a display name in case installers failed
  67.                 if (displayName.substr (displayName.length-4) == ".LNK")
  68.                     displayName = displayName.substr (0, displayName.length-4);
  69.                 var item = window.scripts.output.add ("item", displayName);
  70.                 item.info = { displayName:displayName, scriptID:scriptID,
  71.                             status:status, readOnly:(readOnly == true) };
  72.                 window.scripts.info [scriptID] = item.info;
  73.                 // Include path fix: If the 1st script ID is a valid file,
  74.                 // set the include path to the parent of that file
  75.                 if (i == 0 && (scriptID [0] == '/' || scriptID [0] == '~'))
  76.                 {
  77.                     var f = new File (scriptID);
  78.                     if (f.exists)
  79.                         app.includePath = f.parent.absoluteURI;
  80.                 }
  81.             }
  82.         }
  83.         // do we have extra info?
  84.         if (++i < reply.length && reply[i].length && reply [i][0].length)
  85.         {
  86.             // 1st extra line (V48+): the include path
  87.             app.includePath = reply [i][0];
  88.         }
  89.         // If there are any entries, add a blank line so we can deselect/reselect entries
  90.         if (window.scripts.output.items.length)
  91.             window.scripts.output.add ("item", "");
  92.     }
  93.     bt.safeSend();
  94. }
  95.  
  96. // Deselect the current selection. Called when a document is closed.
  97.  
  98. window.scripts.deselect = function()
  99. {
  100.     this.output.selection = null;
  101. }
  102.  
  103. // Load a script from file and bring that doc to the front.
  104.  
  105. window.scripts.loadFile = function (scriptID)
  106. {
  107.     var doc;
  108.     var file = new File (scriptID);
  109.     // Try to find an existing doc
  110.     for (var i = 0; i < documents.length; i++)
  111.     {
  112.         doc = documents [i];
  113.         if (doc.scriptID == scriptID)
  114.         {
  115.             // the doc is already present, so reload
  116.             doc.load (new File (scriptID));
  117.             window.breakpoints.update();
  118.             document = doc;
  119.             return doc;
  120.         }
  121.     }
  122.     // not found: create a new document
  123.     doc = Document.create (file);
  124.     if (doc)
  125.         doc.status = "exec";
  126.     return doc;
  127. }
  128.  
  129. // Get a script from the target app. 
  130.  
  131. window.scripts.loadScript = function (scriptID, title)
  132. {
  133.     if (scriptID [0] == '(')
  134.         return;
  135.     else if (scriptID [0] == '/' || scriptID [0] == '~')
  136.     {
  137.         this.loadFile (scriptID);
  138.         return;
  139.     }
  140.     var bt = BridgeTalk.create (currentDebugger.target, "GetScript");
  141.     bt.headers.Engine = currentDebugger.engine;
  142.     bt.headers.ScriptID = scriptID;
  143.     // attach additional data for onResult()
  144.     bt.engine = currentDebugger.engine;
  145.     bt.title = title;
  146.     bt.dbg = currentDebugger;    // in case we switched away before the reply comes in
  147.  
  148.     bt.onOwnResult = function (bt)
  149.     {
  150.         // Try to find the script if already loaded
  151.         var target = bt.sender.replace ("#estk", "");
  152.         // add in the BT name again
  153.         var scriptID = this.headers.ScriptID;
  154.         var doc = documents.find (scriptID);
  155.         if (!doc)
  156.         {
  157.             // new doc: try to find the title in the list of scripts
  158.             if (!this.title)
  159.             {
  160.                 var info = window.scripts.info [scriptID];
  161.                 if (info)
  162.                     this.title = info.displayName;
  163.                 else
  164.                     // fallback: use the display name as title
  165.                     this.title = BridgeTalk.getTargetDisplayName (target);
  166.             }
  167.             doc = Document.create (this.title, bt.body, scriptID);
  168.         }
  169.         else
  170.         {
  171.             // make sure that the text is displayed.
  172.             doc.text = bt.body;
  173.             window.breakpoints.update();
  174.         }
  175.         // set target and engine
  176.         var info = window.scripts.info [scriptID];
  177.         doc.target = target;
  178.         doc.engine = this.engine;
  179.         doc.status = info ? info.status : "exec";
  180.         doc.readOnly = info ? info.readOnly : true;
  181.         // To be on the safe side, mark the script received as read only
  182.         // if there is no script ID.
  183.         if (!scriptID.length)
  184.             doc.readOnly = true;
  185.  
  186.         app.toFront();
  187.         // this may be a reload of a doc
  188.         if (this.dbg && (!this.dbg.document || this.dbg.document.scriptID == doc.scriptID))
  189.             this.dbg.setDocument (doc);
  190.         // reflect the script state etc
  191.         debugMenu.reflectState();
  192.     }
  193.     // Error: tell the user
  194.     bt.onOwnError = function (bt)
  195.     {
  196.         if (this.dbg)
  197.             this.dbg.stop();
  198.         errorBox ("$$$/ESToolkit/Alerts/CannotLoadScript=Cannot load script from target %1!",
  199.                          BridgeTalk.getTargetDisplayName (this.target));
  200.     }
  201.     bt.safeSend();
  202. }
  203.  
  204. // Store the script into the target if appropriate. Return true if a PutScript
  205. // operation was initiated.
  206.  
  207. window.scripts.storeScript = function (doc)
  208. {
  209.     var scriptID = doc.scriptID;
  210.     if (scriptID != '(' && scriptID != '/' && scriptID != '~')
  211.     {
  212.         var bt = BridgeTalk.create (currentDebugger.target, "PutScript");
  213.         bt.headers.Engine = currentDebugger.engine;
  214.         bt.headers.ScriptID = scriptID;
  215.         bt.body = doc.text;
  216.         bt.docTitle = doc.title;
  217.         // use onResult - the result is debugger independent
  218.         bt.onResult = function (bt)
  219.         {
  220.             var doc = documents.find (this.headers.ScriptID);
  221.             if (doc)
  222.                 doc.setSavedState();
  223.             // the scripts pane may have changed due to the save operation
  224.             window.scripts.getScripts();
  225.             this.destroy();
  226.         }
  227.         // use onError - the error is debugger independent
  228.         bt.onError = function (bt)
  229.         {
  230.             errorBox (localize ("$$$/CT/ExtendScript/Errors/Err46=%1 is read only", this.docTitle));
  231.             this.destroy();
  232.         }
  233.         bt.safeSend();
  234.         return true;
  235.     }
  236.     else
  237.         // traditional disk save
  238.         return false;
  239. }
  240.  
  241. // The callback for the output list box is activated when the user
  242. // selects a different script. The code tries to find the document.
  243. // If found, it brings the document to the front. If not, it asks the
  244. // current debugger (who filled in the list) to fetch the script.
  245.  
  246. window.scripts.output.onChange = function()
  247. {
  248.     if (this.selection && this.selection.text.length)
  249.     {
  250.         var info = this.selection.info;
  251.         if (info)
  252.         {
  253.             var scriptID = info.scriptID;
  254.             var doc = documents.find (scriptID);
  255.             if (doc)
  256.                 document = doc;
  257.             else
  258.                 this.parent.loadScript (scriptID, this.selection.text);
  259.         }
  260.     }
  261. }
  262.